package com.neuedu.funlifebbs.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.neuedu.funlifebbs.bean.Comments;
import com.neuedu.funlifebbs.dao.CommentsMapper;
import com.neuedu.funlifebbs.query.CommentsQuery;
import com.neuedu.funlifebbs.service.CommentsService;

/**
 * 
 * @author myh
 * @version 2019年8月19日下午1:44:35
 *
 */
@Service
public class CommentsServiceImpl implements CommentsService {

	@Autowired
	CommentsMapper commentsMapper;

	@Override
	public Comments findById(int id) {
		return commentsMapper.findById(id);
	}

	@Override
	public List<Comments> findAll() {
		return commentsMapper.findAll();
	}

	@Override
	public List<Comments> findByTopicId(int id) {
		return commentsMapper.findByTopicId(id);
	}

	@Override
	public PageInfo<Comments> query(CommentsQuery commentsQuery) {
		if (commentsQuery.isPaging()) {
			// 使用分页插件
			Page<Comments> pageInfo = PageHelper.startPage(
					commentsQuery.getPageNum(), commentsQuery.getLimit());
			commentsMapper.query(commentsQuery);
			return pageInfo.toPageInfo();
		} else {

			PageInfo<Comments> pageInfo = new PageInfo<Comments>(
					commentsMapper.query(commentsQuery));
			return pageInfo;
		}
	}

	@Override
	public int add(Comments comments) {
		return commentsMapper.add(comments);
	}

	@Override
	public int deleteById(int id) {
		return commentsMapper.deleteById(id);
	}

	@Override
	public int update(Comments comments) {
		return commentsMapper.update(comments);
	}

}
